package com.pubinfo.passbook.data.controller.sync;

import com.mashape.unirest.http.exceptions.UnirestException;
import com.pubinfo.passbook.common.model.bo.valueAddedTax.InputParamBody;
import com.pubinfo.passbook.common.model.vo.base.JsonResult;
import com.pubinfo.passbook.data.service.SynWriteoffInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;

@RestController
@RequestMapping(value = "debug/SynWriteoffInfo")
@Api(tags = "同步财辅报账单状态")
@Slf4j
public class SynWriteoffInfoController
{
    @Autowired
    SynWriteoffInfoService synWriteoffInfoService;

    @PostMapping("synWriteoffInfo")
    @ApiOperation(value = "同步报账单信息")
    public JsonResult<Boolean> synWriteoffInfo(@RequestBody InputParamBody inputParamBody) throws UnirestException {
        return JsonResult.success(synWriteoffInfoService.synWriteoffInfo(inputParamBody));
    }

    @PostMapping("synWriteoffInfoList")
    @ApiOperation(value = "同步一段时间内的票据信息")
    public JsonResult<Boolean> synWriteoffInfoList(String startTime, String endTime) throws UnirestException, ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return JsonResult.success(synWriteoffInfoService.synWriteoffInfoList(sdf.parse(startTime),sdf.parse(endTime)));
    }

    @PostMapping("synYesterdayWriteoffInfo")
    @ApiOperation(value = "同步前一天的票据信息")
    public JsonResult<Boolean> synWriteoffInfoList() throws UnirestException{
        return JsonResult.success(synWriteoffInfoService.synYesterdayWriteoffInfo());
    }

    @PostMapping("updateWriteoffInfo")
    @ApiOperation(value = "更新所有需要更新的数据")
    public JsonResult<Boolean> updateWriteoffInfo() throws UnirestException{
        return JsonResult.success(synWriteoffInfoService.updateWriteoffInfo());
    }

    @PostMapping("claimFeedbackByWriteoffInstanceCode")
    @ApiOperation(value = "回传单张报账单")
    public void claimFeedbackByWriteoffInstanceCode(String writeoffInstanceCode) throws UnirestException{
        synWriteoffInfoService.claimFeedbackByWriteoffInstanceCode(writeoffInstanceCode);
    }
}
